package com.yy.redisCache.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.redisCache.dao.RedisTestDao;
import com.yy.redisCache.pojo.RedisTest;
import com.yy.redisCache.service.RedisTestService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author young
 * @date 2022/9/4 13:08
 * @description: service实现类
 */
@Service
@CacheConfig(cacheNames = "test")//缓存名，和管理器中配置的一致
public class RedisTestServiceImpl extends ServiceImpl<RedisTestDao, RedisTest> implements RedisTestService {
    @Resource
    private RedisTestDao redisTestDao;

    /**
     * 查寻10000条数据
     * @return
     * key 可为空，指定需按照SpEL编写
     * unless 不缓存的条件 条件为true不缓存
     */
    @Override
    @Cacheable(key = "'allUser'",unless = "#result==null")//#result返回结果
    public List<RedisTest> list() {
        QueryWrapper<RedisTest> wrapper = new QueryWrapper<>();
        wrapper.le("id",10000);
        return redisTestDao.selectList(wrapper);
    }


    /**
     * 批量查询
     * @param idList
     * @return
     */
    @Override
    public List<RedisTest> listByIds(Collection<? extends Serializable> idList) {
        return super.listByIds(idList);
    }
    /**
     * 删除批量信息
     * @param list
     * @return
     */
    @CacheEvict
    @Override
    public boolean removeByIds(Collection<?> list) {
        return super.removeByIds(list);
    }
    
    /**
     * 修改某个对象
     * @param entity
     * @return
     */
    @Override
    @CachePut
    public boolean updateById(RedisTest entity) {
        return super.updateById(entity);
    }

}
